define([], function () {

    var $cs = {};

//======================================================================================================================
//region MapBox Utils For Matrix-based Camera Syncing : MapBox Side
//======================================================================================================================

    function getCenterMercatorCoord(bmap, dx, dy) {
        if (!bmap) return;
        var transform = bmap.transform;
        return bmap.transform.pointCoordinate({
            x: transform.width / 2 + (dx || 0),
            y: transform.height / 2 + (dy || 0)
        });
    }

    function getMercatorPerScreenPx(bmap) {
        var cen1 = getCenterMercatorCoord(bmap, 0, 0);
        var cen2 = getCenterMercatorCoord(bmap, 1, 0);
        // mercator/screenPx
        var mercatorPerPx = Math.hypot(cen1.x - cen2.x, cen1.y - cen2.y);
        return mercatorPerPx;
    }

    function getMeterPerScreenPx(bmap) {
        var mercatorPerPx = getMercatorPerScreenPx(bmap);
        var cen = getCenterMercatorCoord(bmap, 0, 0);
        // mercator/meter
        var unitPerMeter = cen.meterInMercatorCoordinateUnits();
        // meter/screenPx
        var meterPerPx = mercatorPerPx / unitPerMeter;
        return meterPerPx;
    }

    function getLngLatCenter(bmap) {
        return bmap.getCenter();
    }

    function getLngLatCenterPair(bmap) {
        var lngLatCenter = getLngLatCenter(bmap);
        return [lngLatCenter.lng, lngLatCenter.lat];
    }

    function getBearing(bmap) {
        var bearingDeg = bmap.getBearing();
        var bearing = bearingDeg * Math.PI / 180;
        return bearing;
    }

    function getPitch(bmap) {
        var pitchDeg = bmap.getPitch();
        var pitch = pitchDeg * Math.PI / 180;
        return pitch;
    }

    function getFov(bmap) {
        return bmap.transform.fov * Math.PI / 180 / 2;
    }

    function beforeLookAt(bmap, func) {
        func(
            getLngLatCenterPair(bmap),
            getMeterPerScreenPx(bmap),
            {},
            -getBearing(bmap),
            getPitch(bmap),
            getFov(bmap)
        );
    }

//======================================================================================================================
//endregion
//======================================================================================================================

    $cs.beforeLookAt = beforeLookAt;

    return $cs;

});